package com.lansea.wms.model;


import com.lansea.wms.entity.ValidClass;
import com.lansea.wms.enums.MaterialTypeEnum;
import com.lansea.wms.model.base.BaseUser;
import com.lansea.wms.util.EnumUtil;
import com.lansea.wms.validate.CodeValidate;
import com.lansea.wms.validate.NameValidate;
import com.lansea.wms.validate.RemarkValidate;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import org.springframework.stereotype.Repository;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
@Data
@Repository
@ApiModel(value = "Material", description = "成产原料")
public class Material extends BaseUser {

    @Min(value = 1, message = "id 非法", groups = {ValidClass.EditForm.class})
    private Integer id;

    @CodeValidate
    private String code;

    @NameValidate
    private String name;

    @Min(value = 1, message = "请选择类别")
    private Integer type;

    @Min(value = 1, message = "请选择分类")
    private Integer categoryId;

    @Min(value = 1, message = "请选择单位")
    private Integer unitId;

    @Max(value = 100000, message = "安全库存取值为 0-100000 之间")
    private Integer safeNum;

    @Max(value = 100000, message = "有效天数取值为 0-100000 之间")
    private Integer validDay;

    @RemarkValidate
    private String remark;


    private String categoryName;
    private String unitName;

    private String typeName;


    public String getTypeName() {
        MaterialTypeEnum e = EnumUtil.valueOf(MaterialTypeEnum.class, type);
        if (e == null) {
            return "";
        }
        return e.getValue();
    }


}
